package config

import (
	"gopkg.in/yaml.v3"
	"io/ioutil"
	"log"
)

type ConfigWechat struct {
	MchAPIv3Key                string `yaml:"mchAPIv3Key"`
	AppId                      string `yaml:"appId"`
	MchId                      string `yaml:"mechId"`
	MchCertificateSerialNumber string `yaml:"mchCertificateSerialNumber"`
	Path                       string `yaml:"path"`
	CallbackUrl                string `yaml:"callbackUrl"`
}

type ConfigAliPay struct {
	PrivateKey        string `yaml:"privateKey"`
	AppPublicCert     string `yaml:"appPublicCert"`
	AliPayPayRootCert string `yaml:"aliPayPayRootCert"`
	AliPayPublicCert  string `yaml:"aliPayPublicCert"`
	AppId             string `yaml:"appId"`
	CallbackUrl       string `yaml:"callbackUrl"`
	ApiKey            string `yaml:"apiKey"`
}

type ConfigAll struct {
	Port   string       `yaml:"port"`
	Wechat ConfigWechat `yaml:"wechat"`
	AliPay ConfigAliPay `yaml:"aliPay"`
}

var Config ConfigAll

func Init(filename string) {
	conf := new(ConfigAll)
	yamlFile, err := ioutil.ReadFile(filename)
	if err != nil {
		log.Printf("yamlFile.Get err #%v ", err)
	}
	err = yaml.Unmarshal(yamlFile, conf)
	if err != nil {
		log.Fatalf("Unmarshal: %v", err)
	}
	Config = *conf
}
